package com.sdweizan.sdk.bytedance.api.impl;

import com.alibaba.fastjson.TypeReference;
import com.sdweizan.sdk.bytedance.api.BdApiService;
import com.sdweizan.sdk.bytedance.bean.order.BdOrderPushRequest;
import com.sdweizan.sdk.bytedance.bean.order.BdOrderPushResponse;
import com.sdweizan.sdk.bytedance.bean.payment.BdCreateOrderRequest;
import com.sdweizan.sdk.bytedance.bean.payment.BdCreateOrderResponse;
import com.sdweizan.sdk.bytedance.bean.payment.BdQueryOrderRequest;
import com.sdweizan.sdk.bytedance.bean.payment.BdQueryOrderResponse;
import com.sdweizan.sdk.bytedance.bean.refund.BdCreateRefundRequest;
import com.sdweizan.sdk.bytedance.bean.refund.BdCreateRefundResponse;
import com.sdweizan.sdk.bytedance.bean.refund.BdQueryRefundRequest;
import com.sdweizan.sdk.bytedance.bean.refund.BdQueryRefundResponse;
import com.sdweizan.sdk.bytedance.error.BdErrorException;
import lombok.AllArgsConstructor;

/** 抖音-担保交易服务 * */
@AllArgsConstructor
public class BdGuaranteeTransactionService {
  private final BdApiService bdApiService;

  public BdCreateOrderResponse createOrder(BdCreateOrderRequest bdCreateOrderRequest)
      throws BdErrorException {
    return bdApiService.post(bdCreateOrderRequest, new TypeReference<BdCreateOrderResponse>() {});
  }

  public BdQueryOrderResponse queryOrder(BdQueryOrderRequest bdQueryOrderRequest)
      throws BdErrorException {
    return bdApiService.post(bdQueryOrderRequest, new TypeReference<BdQueryOrderResponse>() {});
  }

  public BdCreateRefundResponse createRefund(BdCreateRefundRequest bdCreateRefundRequest)
      throws BdErrorException {
    return bdApiService.post(bdCreateRefundRequest, new TypeReference<BdCreateRefundResponse>() {});
  }

  public BdQueryRefundResponse queryRefund(BdQueryRefundRequest bdQueryRefundRequest)
      throws BdErrorException {
    return bdApiService.post(bdQueryRefundRequest, new TypeReference<BdQueryRefundResponse>() {});
  }

  public BdOrderPushResponse pushOrder(BdOrderPushRequest bdOrderPushRequest)
      throws BdErrorException {
    bdOrderPushRequest.setAccessToken(bdApiService.getAccessToken(false));
    bdOrderPushRequest.setAppName("douyin");
    return bdApiService.post(bdOrderPushRequest, new TypeReference<BdOrderPushResponse>() {});
  }
}
